/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.liquidByte.trafficMustang.server.dao;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.liquidByte.trafficMustang.server.dataModel.Avaliacao;
import org.liquidByte.trafficMustang.server.dataModel.Usuario;
import org.liquidByte.trafficMustang.server.repository.AvaliacaoRepository;

/**
 *
 * @author Alexandre
 */
@Stateless
public class AvaliacaoDAO extends PersistableDAO<Avaliacao> implements AvaliacaoRepository {

    public AvaliacaoDAO() {
        super(Avaliacao.class);
    }

    public List<Avaliacao> get(Usuario avaliador, boolean pendente) {
        EntityManager em = this.getEntityManager();
        CriteriaBuilder builder = em.getCriteriaBuilder();
        
        CriteriaQuery<Avaliacao> q = builder.createQuery(Avaliacao.class);
        Root<Avaliacao> root = q.from(Avaliacao.class);
        q.select(root);
        
        q.where(builder.equal(root.get("usrIdAvlr"), avaliador),
                builder.equal(root.get("avalPend"), pendente));
        
        return em.createQuery(q).getResultList();
    }
}
